#include<iostream>
#include<string>
#include<unordered_map>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
string a[N], b[N];
unordered_map<string, int> hash1;
//int记录的是转换的的次数
queue<string> q;
int p = 0;
string A, B;
int bfs(string A)
{
	if (A == B)
	{
		cout << 0 << endl;
		return 0;
	}
	q.push(A);
	hash1[A] = 0;
	
	while (q.size())
	{
		string s = q.front();
		q.pop();

		if (hash1[s] >= 10) continue;
		if (s == B) return hash1[s];

		for (int i = 0;i < p;i++)
		{
			int pos = 0;
			while (s.find(a[i], pos) != -1)
			{
				 pos = s.find(a[i], pos);
				 //替换逻辑
				 string tmp = s.substr(0, pos) + b[i] + s.substr(pos + a[i].size());
				 pos++;				 
				 if (hash1.count(tmp)) continue;
				 hash1[tmp] = hash1[s] + 1;
				 q.push(tmp);
			}
		}
	}
	return 0;
}

int main()
{
	cin >> A >> B;
	
	while (cin >> a[p]>>b[p]) p++;//注意这个地方p++不能在while括号里面

	//走dfs
    
	int ret=bfs(A);
	if (ret) cout << ret << endl;
	else cout << "NO ANSWER!" << endl;
	return 0;
}